home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / GC.H < prev    next >
C/C++ Source or Header  |  1989-10-28  |  4KB  |  132 lines

  1. /* -*-C-*-
  2.  
  3. Copyright (c) 1987, 1988, 1989 Massachusetts Institute of Technology
  4.  
  5. This material was developed by the Scheme project at the Massachusetts
  6. Institute of Technology, Department of Electrical Engineering and
  7. Computer Science.  Permission to copy this software, to redistribute
  8. it, and to use it for any purpose is granted, subject to the following
  9. restrictions and understandings.
  10.  
  11. 1. Any copy made of this software must include this copyright notice
  12. in full.
  13.  
  14. 2. Users of this software agree to make their best efforts (a) to
  15. return to the MIT Scheme project any improvements or extensions that
  16. they make, so that these may be included in future releases; and (b)
  17. to inform MIT of noteworthy uses of this software.
  18.  
  19. 3. All materials developed as a consequence of the use of this
  20. software shall duly acknowledge such use, in accordance with the usual
  21. standards of acknowledging credit in academic research.
  22.  
  23. 4. MIT has made no warrantee or representation that the operation of
  24. this software will be error-free, and MIT is under no obligation to
  25. provide any services, by way of maintenance, update, or otherwise.
  26.  
  27. 5. In conjunction with products arising from the use of this material,
  28. there shall be no use of the name of the Massachusetts Institute of
  29. Technology nor of any adaptation thereof in any advertising,
  30. promotional, or sales literature without prior written consent from
  31. MIT in each case. */
  32.  
  33. /* $Header: gc.h,v 9.30 89/10/28 15:38:26 GMT jinx Exp $
  34.  *
  35.  * Garbage collection related macros of sufficient utility to be
  36.  * included in all compilations.
  37.  */
  38.  
  39. /* GC Types. */
  40.  
  41. #ifdef HAS_COMPILER_SUPPORT
  42. #ifndef BAD_TYPES_LETHAL
  43. #ifndef BAD_TYPES_INNOCUOUS
  44. #define BAD_TYPES_INNOCUOUS
  45. #endif /* BAD_TYPES_INNOCUOUS */
  46. #endif /* BAD_TYPES_LETHAL */
  47. #endif /* HAS_COMPILER_SUPPORT */
  48.  
  49. #ifdef BAD_TYPES_INNOCUOUS
  50. #ifdef BAD_TYPES_LETHAL
  51. #include "error: gc.h: BAD_TYPES both lethal and innocuous"
  52. #endif /* BAD_TYPES_LETHAL */
  53. #else /* not BAD_TYPES_INNOCUOUS */
  54. #ifndef BAD_TYPES_LETHAL
  55. #define BAD_TYPES_LETHAL
  56. #endif /* BAD_TYPES_LETHAL */
  57. #endif /* BAD_TYPES_INNOCUOUS */
  58.  
  59. #define GC_Non_Pointer             0
  60. #define GC_Cell                1
  61. #define GC_Pair                2
  62. #define GC_Triple            3
  63. #define GC_Hunk3            3
  64. #define GC_Quadruple            4
  65. #define GC_Hunk4                4
  66. #define GC_Undefined            -1 /* Undefined types */
  67. #define GC_Special            -2 /* Internal GC types */
  68. #define GC_Vector            -3
  69. #define GC_Compiled            -4
  70.  
  71. #ifdef BAD_TYPES_INNOCUOUS
  72. #define INVALID_TYPE_CODE(TC)        GC_Undefined
  73.  
  74. #else /* not BAD_TYPES_INNOCUOUS */
  75.  
  76. /* Some C compilers complain if the expression below does not yield
  77.    a value, and Microcode_Termination yields void.
  78.  */
  79.  
  80. #define INVALID_TYPE_CODE(TC)                        \
  81.   (fprintf(stderr, "\nGC_Type_Code: Bad Type code = 0x%02x\n", TC),    \
  82.    Microcode_Termination(TERM_INVALID_TYPE_CODE),            \
  83.    GC_Undefined)
  84.  
  85. #endif /* BAD_TYPES_INNOCUOUS */
  86.  
  87. #define GC_Type_Code(TC)                        \
  88.  ((GC_Type_Map[TC] != GC_Undefined)    ?                \
  89.   GC_Type_Map[TC]            :                \
  90.   (INVALID_TYPE_CODE(TC)))
  91.  
  92. #define GC_Type(Object)            GC_Type_Code(OBJECT_TYPE (Object))
  93.  
  94. #define GC_Type_Non_Pointer(Object)    (GC_Type(Object) == GC_Non_Pointer)
  95. #define GC_Type_Cell(Object)        (GC_Type(Object) == GC_Cell)
  96. #define GC_Type_List(Object)        (GC_Type(Object) == GC_Pair)
  97. #define GC_Type_Triple(Object)        (GC_Type(Object) == GC_Triple)
  98. #define GC_Type_Quadruple(Object)    (GC_Type(Object) == GC_Quadruple)
  99. #define GC_Type_Undefined(Object)    (GC_Type(Object) == GC_Undefined)
  100. #define GC_Type_Special(Object)        (GC_Type(Object) == GC_Special)
  101. #define GC_Type_Vector(Object)        (GC_Type(Object) == GC_Vector)
  102. #define GC_Type_Compiled(Object)    (GC_Type(Object) == GC_Compiled)
  103.  
  104. /* Overflow detection, various cases */
  105.  
  106. #define GC_ENABLED_P()        (INTERRUPT_ENABLED_P(INT_GC))
  107.  
  108. #define GC_Check(Amount)                        \
  109. (((Amount + Free) >= MemTop) && (GC_ENABLED_P()))
  110.  
  111. #define Space_Before_GC()                        \
  112. ((GC_ENABLED_P()) ?                            \
  113.  ((Free <= MemTop) ? (MemTop - Free) : 0) :                \
  114.  (Heap_Top - Free))
  115.  
  116. #define Request_GC(Amount)                        \
  117. {                                    \
  118.   REQUEST_INTERRUPT(INT_GC);                        \
  119.   GC_Space_Needed = Amount;                        \
  120. }
  121.  
  122. #define SET_MEMTOP(Addr)                        \
  123. {                                    \
  124.   MemTop = Addr;                            \
  125.   COMPILER_SET_MEMTOP();                        \
  126. }
  127.  
  128. #define Set_Stack_Guard(Addr)                        \
  129. {                                    \
  130.   Stack_Guard = Addr;                            \
  131. }
  132.